# -*- coding: utf-8 -*-
# Create time: 2020-03-13 14:51
# Author:Rongzhikai
"""
注意：导入对应的登录模块
"""
import unittest
import warnings
from ddt import *
from libs.read_exceldata import Datafromexcel
from libs.run_api import Run_api
from somedebug.login import dagl_login_user
from libs.logger import Logger
from libs.global_vars import gvar


@ddt
class MyUnitTest(unittest.TestCase):
    # 获取Excel测试用例数据
    test_datas = Datafromexcel().getdata()

    @classmethod
    def setUpClass(cls) -> None:
        warnings.simplefilter('ignore', ResourceWarning)  # 取消不给显示警告
        cls.data_excel = Datafromexcel()  # 待记录测试结果到Excel表格
        cls.mylog = Logger()  # 记录运行日志
        cls.session = dagl_login_user()
        cls.gorun = Run_api(cls.session)  # 主要发送请求，里边也包含session

    def setUp(self) -> None:
        print('this is setUp!')
        pass

    def tearDown(self) -> None:
        # print('this is setDown!')
        pass

    @classmethod
    def tearDownClass(cls) -> None:
        cls.gorun.session.close()
        # 发送邮件通知，配合HtmlTestRunner，发送结果附件和网页报告-=-====
        print(gvar.pass_count)
        print(gvar.fail_count)

    # ddt数据驱动，方便的遍历测试用例数据
    @data(*test_datas)
    @unpack
    def test_my02(self, project, module, case_id, case_name, description, is_Run, url, method, headers, cookies, params,
                  body, globalVariable, assertRes, result, tester):

        # 判断是否运行
        if str(is_Run).upper() == 'Y':
            gvar.pass_count += 1
        elif str(is_Run).upper() == 'N':
            gvar.fail_count += 1

if __name__ == '__main__':
    unittest.main()
